﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Threading;
using System.Windows.Media.Effects;
using System.Windows.Shapes;

namespace MapSurface
{
    public class BorderElement:Grid
    {
        public Grid Content = null;
        public Rectangle bottomLeftSizeGrip = null;
        public Rectangle topRightSizeGrip = null;
        public Rectangle bottomRightSizeGrip = null;
        public Rectangle topLeftSizeGrip = null;
        public Rectangle bottomSizeGrip = null;
        public Rectangle topSizeGrip = null;
        public Rectangle rightSizeGrip = null;
        public Rectangle leftSizeGrip = null;
        public WindowResizer wr = null;

        public BorderElement(String name, Object content)
        {
            #region IntializeComponents
            RowDefinition r1 = new RowDefinition();
            r1.Height = new GridLength(20);
            RowDefinition r2 = new RowDefinition();
            r2.Height = GridLength.Auto;
            this.RowDefinitions.Add(r1);
            this.RowDefinitions.Add(r2);
            this.RowDefinitions.Add(r1);
            ColumnDefinition c1 = new ColumnDefinition();
            c1.Width = new GridLength(20); ;
            ColumnDefinition c2 = new ColumnDefinition();
            c2.Width = GridLength.Auto;
            this.ColumnDefinitions.Add(c1);
            this.ColumnDefinitions.Add(c2);
            this.ColumnDefinitions.Add(c1);
            Name = name;
            leftSizeGrip = new Rectangle();
            leftSizeGrip.Name = "leftSizeGrip";
            leftSizeGrip.Fill = Brushes.Red;
            SetColumn(leftSizeGrip, 0);
            SetRow(leftSizeGrip, 1);

            rightSizeGrip = new Rectangle();
            rightSizeGrip.Name = "rightSizeGrip";
            rightSizeGrip.Fill = Brushes.Red;
            SetColumn(rightSizeGrip, 2);
            SetRow(rightSizeGrip, 1);

            topSizeGrip = new Rectangle();
            topSizeGrip.Name = "topSizeGrip";
            topSizeGrip.Fill = Brushes.Red;
            SetColumn(topSizeGrip, 1);
            SetRow(topSizeGrip, 0);

            bottomSizeGrip = new Rectangle();
            bottomSizeGrip.Name = "bottomSizeGrip";
            bottomSizeGrip.Fill = Brushes.Red;
            SetColumn(bottomSizeGrip, 1);
            SetRow(bottomSizeGrip, 2);

            topLeftSizeGrip = new Rectangle();
            topLeftSizeGrip.Name = "topLeftSizeGrip";
            topLeftSizeGrip.Fill = Brushes.Red;
            SetColumn(topLeftSizeGrip, 0);
            SetRow(topLeftSizeGrip, 2);

            bottomRightSizeGrip = new Rectangle();
            bottomRightSizeGrip.Name = "bottomRightSizeGrip";
            bottomRightSizeGrip.Fill = Brushes.Red;
            SetColumn(bottomRightSizeGrip, 2);
            SetRow(bottomRightSizeGrip, 2);

            topRightSizeGrip = new Rectangle();
            topRightSizeGrip.Name = "topRightSizeGrip";
            topRightSizeGrip.Fill = Brushes.Red;
            SetColumn(topRightSizeGrip, 2);
            SetRow(topRightSizeGrip, 0);

            bottomLeftSizeGrip = new Rectangle();
            bottomLeftSizeGrip.Name = "bottomLeftSizeGrip";
            bottomLeftSizeGrip.Fill = Brushes.Red;
            SetColumn(bottomLeftSizeGrip, 0);
            SetRow(bottomLeftSizeGrip, 2);

            #endregion

            Content = new Grid();
            Content.Name = "BorderContent";
            SetRow(Content, 1);
            SetColumn(Content, 1);
            windowResize();
        }
        private void windowResize()
        {
            wr = new WindowResizer(this);
            wr.addResizerRight(rightSizeGrip);
            wr.addResizerLeft(leftSizeGrip);
            wr.addResizerUp(topSizeGrip);
            wr.addResizerDown(bottomSizeGrip);
            wr.addResizerLeftUp(topLeftSizeGrip);
            wr.addResizerRightUp(topRightSizeGrip);
            wr.addResizerLeftDown(bottomLeftSizeGrip);
            wr.addResizerRightDown(bottomRightSizeGrip);

        }

    }
}
